using UnityEngine;
using System;



public class SAMapGrid
{

	public const int GridX = 64;
	public const int GridY = 48;

	public const int GridInclined = 40;
	public const int GridInclinedHalf = 20;


	public const int GridXHalf = 32;
	public const int GridYHalf = 24;
	public const int GridXHalfHalf = 16;
	public const int GridYHalfHalf = 12;
	
	public const float GridPX = 0.8f;
	public const float GridPY = 0.6f;
	
	public const float GridXFour = 16;
	public const float GridYFour = 12;

	public float realPosX = 0.0f;
	public float realPosY = 0.0f;
	
	public int posX = 0;
	public int posY = 0;

	public bool checkPos()
	{
		return realPosX == posX * SAMapGrid.GridXHalf + posY * SAMapGrid.GridXHalf && 
			realPosY == -posX * SAMapGrid.GridYHalf + posY * SAMapGrid.GridYHalf;
	}

	
	public bool checkPosReal( SAMapGrid grid ) 
	{
		return grid.realPosX == realPosX && grid.realPosY == realPosY;
	}

	public bool checkPos( SAMapGrid grid ) 
	{
		return grid.posX == posX && grid.posY == posY;
	}

	public void move( int direct )
	{
		switch( direct )
		{
		case (int)SAMapDirectionType.EAST:
			posX++;
			break;
		case (int)SAMapDirectionType.SOUTH:
			posY++;
			break;
		case (int)SAMapDirectionType.WEST:
			posX--;
			break;
		case (int)SAMapDirectionType.NORTH:
			posY--;
			break;
		case (int)SAMapDirectionType.NORTHEAST:
			posX++;posY--;
			break;
		case (int)SAMapDirectionType.NORTHWEST:
			posX--;posY--;
			break;
		case (int)SAMapDirectionType.SOUTHEAST:
			posX++;posY++;
			break;
		case (int)SAMapDirectionType.SOUTHWEST:
			posX--;posY++;
			break;
		}

		setValue( posX , posY );
	}

	public bool isAround( SAMapGrid grid )
	{
		if ( grid.posX == posX + 1 && grid.posY == posY ) 
		{
			return true;
		}
		
		if ( grid.posX == posX - 1 && grid.posY == posY ) 
		{
			return true;
		}
		
		if ( grid.posX == posX && grid.posY == posY + 1 ) 
		{
			return true;
		}
		
		if ( grid.posX == posX && grid.posY == posY - 1 ) 
		{
			return true;
		}
		
		if ( grid.posX == posX - 1 && grid.posY == posY - 1 ) 
		{
			return true;
		}
		
		if ( grid.posX == posX + 1 && grid.posY == posY - 1 ) 
		{
			return true;
		}
		
		if ( grid.posX == posX - 1 && grid.posY == posY + 1 ) 
		{
			return true;
		}
		
		if ( grid.posX == posX + 1 && grid.posY == posY + 1 ) 
		{
			return true;
		}
		
		return false;
	}

	public void setValue( int x , int y )
	{
		posX = x;
		posY = y;
		
		realPosX = posX * GridXHalf + posY * GridXHalf;
		realPosY = posX * GridYHalf - posY * GridYHalf;
	}

	public SAMapGrid ( int x , int y )
	{
		setValue( x , y );
	}

	public SAMapGrid ()
	{

	}


}

